package com.example.imtoken.modules.main.wallet.details.trade.transfer.set_price

import android.annotation.SuppressLint
import android.os.Bundle
import android.view.View
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.example.imtoken.R
import com.example.imtoken.databinding.ItemSettingMinerFeeBinding
import com.example.imtoken.entitys.http.Step

class SettingMinerFeeAdapter(layoutResId: Int) :

    BaseQuickAdapter<Step, BaseDataBindingHolder<ItemSettingMinerFeeBinding>>(layoutResId) {

    private var uint: String? = null
    fun setUint(uint: String) {
        this.uint = uint
    }

    @SuppressLint("SetTextI18n")
    override fun convert(holder: BaseDataBindingHolder<ItemSettingMinerFeeBinding>, item: Step) {
        if (item.isSelected) {
            holder.dataBinding?.ivSelected?.visibility = View.VISIBLE
        } else {
            holder.dataBinding?.ivSelected?.visibility = View.INVISIBLE
        }
        holder.dataBinding?.tvName?.text = item.name
        holder.dataBinding?.tvUint?.text = "${item.gas} $uint"
        holder.dataBinding?.tvMinute?.text =
            context.getString(R.string.estimatedTimeData, item.minute.toString())
    }

    override fun convert(
        holder: BaseDataBindingHolder<ItemSettingMinerFeeBinding>,
        item: Step,
        payloads: List<Any>
    ) {
        super.convert(holder, item, payloads)
        val bundle = payloads[0] as Bundle
        val b = bundle.getBoolean("isSelected")
        if (b) {
            holder.dataBinding?.ivSelected?.visibility = View.VISIBLE
        } else {
            holder.dataBinding?.ivSelected?.visibility = View.INVISIBLE
        }
    }
}